<!doctype html>

<html>

<head>

<title>

Francisco,Raphael,gabriel e Rafael

</title>

<script src="js/Background.js"></script>
<script src="js/LEVEL_1.js"></script>
<script src="js/cena_creditos.js"></script>
<script src="js/cena.js"></script>
<script src="js/Introducao.js"></script>
<script src="js/botao.js"></script>
<script src="js/Instrucao.js"></script>
<script src="js/nuvem.js"></script>
<script src="js/shoot.js"></script>
<!--RENOMEAR PRA ASTEROID.js-->
<script src="js/shoot-old.js"></script>

</head>


<body>

<!--canvas principal onde acontece o jogo-->
<canvas width=" 841" height="595" id="main" style="border:1px solid #000000;"></canvas>

<script>

var canvas = document.getElementById("main");
var screen = canvas.getContext("2d");

var SCREENWIDTH =  841;
var SCREENHEIGHT = 595;

var paused = false;

var introducao = new Introducao();

var creditos = new Creditos();

var instrucao = new Instrucao();

var level_1 = new Level_1();

var SCENES = { INTRODUCAO: 0, CREDITOS: 1, LEVEL_1: 2, INSTRUCAO:3 }

var currentScene = SCENES.INTRODUCAO;

load();

function load()
{	
console.log("load");

if((true))//to do...
{	
console.log("carreguei");

loop();
}
else
{
console.log("nao carreguei");

setTimeout(load, 30 );
}
}

function loop()
{
	//console.log("loop");

//o loop do jogo faz chamadas para update e draw

update();

draw();

//o loop do jogo se chama a cada 30 ms, +- 30 FPS (1/30) ~ 33 fps
setTimeout(loop, 1000/60 );

}	

		function update()
{	
		switch(currentScene)
	{
		
	case SCENES.INTRODUCAO:
		{
			introducao.update();	
		}
			break;
			

	case SCENES.CREDITOS:
		{
			creditos.update();
		}
		break;
		
	case SCENES.INSTRUCAO:
		{
			instrucao.update();
		}
		break;

	case SCENES.LEVEL_1:
		{
		level_1.update();
		}
		break;
	}

}

function draw()		
{
			clear();

			switch(currentScene)
			{
				case SCENES.INTRODUCAO:
				{
 					introducao.draw();
				}
				break;
				case SCENES.CREDITOS:
				{
					creditos.draw();
				}
				break;

			case SCENES.INSTRUCAO:
			{
				instrucao.draw();
			}
			break;
			
			case SCENES.LEVEL_1:
			{
			level_1.draw();
			}
			break;

			
		}

		}

function clear()
{
screen.clearRect(0,0,841,595);
}


window.addEventListener('keydown', key_down, true);
window.addEventListener('keyup', key_up, true);
window.addEventListener('mousemove', mouse_move, true);
window.addEventListener('mouseup', mouse_up, true);
window.addEventListener('mousedown', mouse_down, true);

function key_down(key)
{
switch(currentScene)
{
case SCENES.INTRODUCAO:
{
	introducao.key_down(key);
}
break;

case SCENES.CREDITOS:
{
	creditos.key_down(key);
}
break;

case SCENES.INSTRUCAO:
{
	instrucao.key_down(key);
}

break;
case SCENES.LEVEL_1:
{
	level_1.key_down(key);
}
break;
}


}

function key_up(key)
{
switch(currentScene)
{
	
	case  SCENES.INTRODUCAO:
{
	introducao.key_up(key);
}
break;

case SCENES.CREDITOS:
{
	creditos.key_up(key);
}
break;

case SCENES.INSTRUCAO:
{
	instrucao.key_up(key);
}
break;

case SCENES.LEVEL_1:
{
	level_1.key_up(key);
}
break;
}	
}

function mouse_move(mouse)
{

}

function mouse_up(mouse)
{

}

function mouse_down(mouse)

{
switch(currentScene)
{
case  SCENES.INTRODUCAO:
{
	//console.log("mous x " + mouse.x, "mouse y " + mouse.y)	
	introducao.mouse_down(mouse);
}
break;
case SCENES.CREDITOS:
{
creditos.mouse_down(mouse);
}
break;

case SCENES.INSTRUCAO:
{
instrucao.mouse_down(mouse);
}
break;

case SCENES.LEVEL_1:
{
level_1.mouse_down(mouse);
}
break;
}
}

function Collide(x1, y1, w1, h1, x2, y2, w2, h2)
{	
if((x1+w1<x2)//se rect1 esquerda rect2
||(x1>x2+w2)//se rect1 direita rect2
||(y1+h1<y2)//se rect1 acima rect2
||(y1>y2+h2))//se rect1 abaixo rect2
{
return false;//nao colidiu
}
else
{
return true;//colidiu
}
}


</script>

</body>

</html>
